package com.exercise.widgets.chip

import android.content.Context
import android.content.Intent
import android.os.Bundle
import android.view.LayoutInflater
import androidx.activity.enableEdgeToEdge
import androidx.appcompat.app.AppCompatActivity
import androidx.core.view.ViewCompat
import androidx.core.view.WindowInsetsCompat
import com.exercise.struct.base.BaseActivity
import com.exercise.struct.viewmodel.BaseViewModel
import com.exercise.widgets.R
import com.exercise.widgets.chip.wrapper.DetectType
import com.exercise.widgets.chip.wrapper.DynamicChipGroupAdapter
import com.exercise.widgets.databinding.ActivityChipBinding
import com.google.android.material.snackbar.Snackbar

class ChipActivity : BaseActivity<BaseViewModel, ActivityChipBinding>() {
    override val bindingInflater: (LayoutInflater) -> ActivityChipBinding
        get() = ActivityChipBinding::inflate
    override val modelClass: Class<BaseViewModel>
        get() = BaseViewModel::class.java

    override fun initData() {
    }

    override fun initView() {
        val dataList = listOf(
            DetectType("全部", "01"),
            DetectType("测试数据啊啊", "01"),
            DetectType("我", "01"),
            DetectType("测试数据啊啊啊", "01"),
            DetectType("其他", "01"),
        )
        val dynamicChipGroupAdapter = DynamicChipGroupAdapter(dataList.toMutableList())
        binding.dynamicChipGroup.setAdapter(dynamicChipGroupAdapter)

        val dataList2 = listOf(
            DetectType("全部2", "01"),
            DetectType("测试数据啊啊2", "01"),
            DetectType("我2", "01"),
            DetectType("测试数据啊啊啊2", "01"),
            DetectType("其他2", "01"),
        )
        dynamicChipGroupAdapter.resetCheckedIndex(1,2)
        dynamicChipGroupAdapter.setList(dataList2)

        binding.btnShowChecked.setOnClickListener {
            Snackbar.make(
                binding.root,
                "${dynamicChipGroupAdapter.checkedItems.joinToString { it.name }}",
                Snackbar.LENGTH_SHORT
            ).show()
        }
        binding.btnClearChecked.setOnClickListener {
            binding.dynamicChipGroup.clearCheck()
        }
        binding.btnResetChecked.setOnClickListener {
            dynamicChipGroupAdapter.resetCheckedIndex(1)
        }
    }

    companion object {
        fun start(context: Context) {
            Intent(context, ChipActivity::class.java).also {
                context.startActivity(it)
            }
        }
    }
}